/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.TimeClockServer.messages.rx;

import TimeRecording.TimeClockServer.messages.ClockMessage;

/**
 *
 * @author david
 */
public class RxClockMessage extends ClockMessage {

    private final static int MSG_CODE_INDEX = 1;

    // The message broken down into its comoponent parts
    protected SplitMessage splitMsg = null;

    /**
     * This constructor will squirrel away the bytes of the message in the base
     * class then split the content into its component parts to be consumed by
     * business login.
     *
     * @param msg the full received message including header and footer
     */
    public RxClockMessage(byte[] msg) {
        super(msg);
        splitMsg = new SplitMessage(msg);
    }

    /**
     * This constructor will squirrel away the bytes of the message in the base
     * class then split the content into its component parts to be consumed by
     * business login.  The supplied key map facilitates keys access to the
     * component parts of the supplied message.
     *
     * @param msg the full received message including header and footer
     * @param keys allows parts of the message to be access by key
     */
    public RxClockMessage(byte[] msg, SplitMessage keys) {
        super(msg);
        splitMsg = new SplitMessage(msg, keys);
    }

    public String getPart(int index) {
        return splitMsg.getPart(index);
    }

    public String getPart(String key) {
        return splitMsg.getPart(key);
    }

    public int partCount() {
        return splitMsg.partCount();
    }

    public String messageCode() {
        return splitMsg.getPart(MSG_CODE_INDEX);
    }

    public boolean isMsg(String messageCode) {
        return messageCode().equals(messageCode);
    }
}